package org.rxc.base.service.impl;

import org.rxc.base.mapper.BaseMapper;
import org.rxc.base.query.BaseQuery;
import org.rxc.base.service.IBaseService;
import org.rxc.base.utils.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public class BaseServiceImpl<T> implements IBaseService<T>{
        @Autowired
        private BaseMapper<T> baseMapper;
        @Override
        @Transactional
        public void save(T t) {
            baseMapper.save(t);
        }

        @Override
        @Transactional
        public void update(T t) {
            baseMapper.update(t);
        }

        @Override
        @Transactional
        public void delete(Long id) {
            baseMapper.delete(id);
        }

        @Override
        public T queryById(Long id) {
            return baseMapper.queryById(id);
        }

        @Override
        public List<T> queryAll() {
            return baseMapper.queryAll();
        }

        @Override
        public PageList<T> queryPage(BaseQuery baseQuery) {
            Long total = baseMapper.count(baseQuery);
            List<T> list = baseMapper.queryPage(baseQuery);
            return new PageList<T>(total,list);
        }

        @Override
        public void batchRemove(List<Long> ids) {
            baseMapper.batchRemove(ids);
        }
    }
